package com.ruoyi.yljf.controller.AdminController;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yljf.domain.Pharmacy;
import com.ruoyi.yljf.service.IPharmacyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门诊医堂Controller
 * 
 * @author TTTc
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/yljf/pharmacy")
public class PharmacyController extends BaseController {
    @Autowired
    private IPharmacyService pharmacyService;

    /**
     * 查询门诊医堂列表
     */
    @PreAuthorize("@ss.hasPermi('yljf:pharmacy:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pharmacy pharmacy) {
        startPage();
        List<Pharmacy> list = pharmacyService.selectPharmacyList(pharmacy);
        return getDataTable(list);
    }

    /**
     * 导出门诊医堂列表
     */
    @PreAuthorize("@ss.hasPermi('yljf:pharmacy:export')")
    @Log(title = "门诊医堂", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Pharmacy pharmacy) {
        List<Pharmacy> list = pharmacyService.selectPharmacyList(pharmacy);
        ExcelUtil<Pharmacy> util = new ExcelUtil<Pharmacy>(Pharmacy.class);
        util.exportExcel(response, list, "门诊医堂数据");
    }

    /**
     * 获取门诊医堂详细信息
     */
    @PreAuthorize("@ss.hasPermi('yljf:pharmacy:query')")
    @GetMapping(value = "/{pharmacyId}")
    public AjaxResult getInfo(@PathVariable("pharmacyId") Long pharmacyId) {
        return success(pharmacyService.getById(pharmacyId));
    }

    /**
     * 新增门诊医堂
     */
    @PreAuthorize("@ss.hasPermi('yljf:pharmacy:add')")
    @Log(title = "门诊医堂", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Pharmacy pharmacy) {
        return toAjax(pharmacyService.save(pharmacy));
    }

    /**
     * 修改门诊医堂
     */
    @PreAuthorize("@ss.hasPermi('yljf:pharmacy:edit')")
    @Log(title = "门诊医堂", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Pharmacy pharmacy) {
        return toAjax(pharmacyService.updateById(pharmacy));
    }

    /**
     * 删除门诊医堂
     */
    @PreAuthorize("@ss.hasPermi('yljf:pharmacy:remove')")
    @Log(title = "门诊医堂", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pharmacyIds}")
    public AjaxResult remove(@PathVariable Long[] pharmacyIds) {
        return toAjax(pharmacyService.removeByIds(Arrays.asList(pharmacyIds)));
    }
}
